﻿using System.Text.RegularExpressions;
using UnityEngine;
namespace DTFramework.Util
{
    /// <summary>
    /// 正则表达式扩展
    /// </summary>
    public static class RegexUtil
    {
        public static class GisLocation
        {
            public static bool IsInRange(Vector2 pos, Vector2[] points)
            {
                //TODO :实现 pos是否在points的范围内
                foreach (var point in points)
                {
                    if (Mathf.Abs(pos.x - point.x) <= 0.0001f && Mathf.Abs(pos.y - point.y) <= 0.0001f)
                    {
                        return true;
                    }
                }
                return false;
            }
            // 判断点是否在矩形内的方法  
            public static bool IsInRange(Vector2 point, Vector2 min, Vector2 max)
            {
                // 检查点的x坐标是否在矩形的x范围内  
                bool isXInside = point.x >= min.x && point.x <= max.x;
                // 检查点的y坐标是否在矩形的y范围内  
                bool isYInside = point.y >= min.y && point.y <= max.y;
                // 如果x和y都在范围内，则点在矩形内  
                return isXInside && isYInside;
            }
            /// <summary>
            ///  经纬度校验
            /// </summary>
            public static bool IsCheckLonLat(string inputLon, string inputLat)
            {
                return IsCheckLon(inputLon) && IsCheckLat(inputLat);
            }
            /// <summary>
            ///  经度校验
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static bool IsCheckLon(string inputValue)
            {
                string pattern = @"^(\-|\+)?(((\d|[1-9]\d|1[0-7]\d|0{1,3})\.\d{0,6})|(\d|[1-9]\d|1[0-7]\d|0{1,3})|180\.0{0,6}|180)$";
                return Regex.IsMatch(inputValue, pattern);
            }
            /// <summary>
            /// 纬度校验
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            public static bool IsCheckLat(string inputValue)
            {
                string pattern = @"^(\-|\+)?([0-8]?\d{1}\.\d{0,6}|90\.0{0,6}|[0-8]?\d{1}|90)$";
                return Regex.IsMatch(inputValue, pattern);
            }
        }
    }
}
